package top.lilele.adminSystem.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.lilele.adminSystem.dto.CommonPageDto;
import top.lilele.adminSystem.dto.IdParams;
import top.lilele.adminSystem.dto.IdsParams;
import top.lilele.adminSystem.dto.PageDto;
import top.lilele.adminSystem.entity.AdminNoticeEntity;
import top.lilele.adminSystem.service.AdminNoticeService;
import top.lilele.adminSystem.utils.BaseResponse;
import top.lilele.adminSystem.utils.ResponseCodeEnum;
import top.lilele.adminSystem.vo.NoticeInfoVo;

import javax.annotation.Resource;

/**
 * @author lilele
 */
@Api(tags = "公告管理")
@RestController
@RequestMapping(value = "notice")
public class AdminNoticeController {

    @Resource
    AdminNoticeService adminNoticeService;

    @ApiOperation(value = "新增公告")
    @PostMapping(value = "add")
    public BaseResponse add(@RequestBody @Validated AdminNoticeEntity adminNoticeEntity) {
        adminNoticeService.add(adminNoticeEntity);
        return BaseResponse.info(ResponseCodeEnum.Success, null);
    }

    @ApiOperation(value = "查询公告列表")
    @PostMapping(value = "queryNoticeList")
    public BaseResponse queryNoticeList(@RequestBody CommonPageDto page) {
        PageDto pageDto = adminNoticeService.queryNoticeList(page);
        return BaseResponse.info(ResponseCodeEnum.Success, pageDto);
    }

    @ApiOperation(value = "删除公告")
    @PostMapping(value = "deleteNoticeByIds")
    public BaseResponse deleteNoticeByIds(@RequestBody IdsParams idsParams) {
        adminNoticeService.deleteNoticeByIds(idsParams.getIds());
        return BaseResponse.info(ResponseCodeEnum.Success, null);
    }

    @ApiOperation(value = "查询公告详情")
    @PostMapping(value = "queryNoticeById")
    public BaseResponse queryNoticeById(@RequestBody @Validated IdParams idParams) {
        AdminNoticeEntity adminNoticeEntity = adminNoticeService.queryNoticeById(idParams.getId());
        return BaseResponse.info(ResponseCodeEnum.Success, adminNoticeEntity);
    }
}
